package com.tube.fiddles.support.dao;

import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.metamodel.Metamodel;

public class GenericDao implements IGenericDao {

    @PersistenceContext
    private EntityManager entityManager;

    public void persist(Object entity) {
        entityManager.persist(entity);
    }

    public <T> T merge(T entity) {
        return entityManager.merge(entity);
    }

    public void remove(Object entity) {
        entityManager.remove(entity);
    }

    public void refresh(Object entity) {
        entityManager.refresh(entity);
    }

    public void refresh(Object entity, LockModeType lockMode) {
        entityManager.refresh(entity, lockMode);
    }

    public void refresh(Object entity, Map<String, Object> properties) {
        entityManager.refresh(entity, properties);
    }

    public void refresh(Object entity, LockModeType lockMode,
            Map<String, Object> properties) {
        entityManager.refresh(entity, lockMode, properties);
    }

    public void clear() {
        entityManager.clear();
    }

    public void detach(Object entity) {
        entityManager.detach(entity);
    }

    public void flush() {
        entityManager.flush();
    }

    public boolean contains(Object entity) {
        return entityManager.contains(entity);
    }

    public Metamodel getMetamodel() {
        return entityManager.getMetamodel();
    }

    public CriteriaBuilder getCriteriaBuilder() {
        return entityManager.getCriteriaBuilder();
    }

    public <T> T getReference(Class<T> entityClass, Object primaryKey) {
        return entityManager.getReference(entityClass, primaryKey);
    }

    public Query createNativeQuery(String sqlString) {
        return entityManager.createNativeQuery(sqlString);
    }

    public Query createNativeQuery(String sqlString, Class<?> resultClass) {
        return entityManager.createNativeQuery(sqlString, resultClass);
    }
    
    public Query createNativeQuery(String sqlString, String resultSetMapping) {
        return entityManager.createNativeQuery(sqlString, resultSetMapping);
    }

    public Query createNamedQuery(String name) {
        return entityManager.createNamedQuery(name);
    }

    public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) {
        return entityManager.createNamedQuery(name, resultClass);
    }

    public Query createQuery(String qlString) {
        return entityManager.createQuery(qlString);
    }

    public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
        return entityManager.createQuery(criteriaQuery);
    }
    
    public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass) {
        return entityManager.createQuery(qlString, resultClass);
    }

    public <T> T find(Class<T> entityClass, Object primaryKey) {
        return entityManager.find(entityClass, primaryKey);
    }
    
    public <T> T find(Class<T> entityClass, Object primaryKey,
            Map<String, Object> properties) {
        return entityManager.find(entityClass, primaryKey, properties);
    }
    
    public <T> T find(Class<T> entityClass, Object primaryKey,
            LockModeType lockMode, Map<String, Object> properties) {
        return entityManager.find(entityClass, primaryKey, lockMode, properties);
    }

}
